package com.coollang.smartbra.presenter;

import android.util.Log;

import com.coollang.smartbra.activity.ShareMapActivity;
import com.coollang.smartbra.base.MyApplication;
import com.coollang.smartbra.model.BaseModel;
import com.coollang.smartbra.model.RunningDataModel;

import java.util.HashMap;
import java.util.Map;

import io.realm.RealmResults;

/**
 * @Auther: Timmy
 * @Data: 2017/7/12
 * @Fuction:
 */

public class ShareMapActivityPresenter extends BasePresenter<BaseModel> {

    private ShareMapActivity mShareMapActivity;

    public ShareMapActivityPresenter(ShareMapActivity shareMapActivity) {
        super(BaseModel.class);
        mShareMapActivity = shareMapActivity;
    }

    @Override
    public void setRequestInfo() {
        setBaseOkgo("action/add-distance-action");
    }

    @Override
    protected Map<String, String> getData() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "21");
        map.put("username", MyApplication.mLogInDataBean.getUsername());
        map.put("ave_heart_rate", mModel.getHeart_rate() + "");
        map.put("max_heart_rate", mModel.getMax_rate() + "");
        map.put("min_heart_rate", mModel.getMin_rate() + "");

        long starttime = mModel.getStarttime();
        long endtime = mModel.getEndtime();
        map.put("sport_duration", endtime - starttime + "");
        map.put("start_time", starttime + "");
        map.put("end_time", endtime + "");
        double mileage = mModel.getMileage();

        map.put("distance", (int) mModel.getMileage() + "");
        map.put("ave_pace", mModel.getFull_speed() + "");
        map.put("max_pace", mModel.getFast_speed() + "");
        map.put("min_pace", mModel.getSlow_speed() + "");

        // 步数 / 时间
        // double frequency = (endtime - starttime) / mModel.getMileage();

        map.put("frequency", (int) mileage + "");
        return map;
    }

    @Override
    protected void parsrData(BaseModel baseModel) {

    }

    private RunningDataModel mModel;

    public RunningDataModel queryRunningData() {
        RealmResults<RunningDataModel> results = mRealm.where(RunningDataModel.class).findAll();
        RunningDataModel model = results.get(results.size() - 1);
        mModel = model;
        return model;
    }
}
